package com.wt.struggle.goodbye.main.activity

import android.Manifest
import android.content.pm.PackageManager
import android.os.Bundle
import android.support.v4.app.ActivityCompat
import android.support.v4.content.ContextCompat
import com.wt.struggle.goodbye.R
import com.wt.struggle.goodbye.base.ProActivity
import com.wt.struggle.goodbye.info.NetInfo
import com.xin.lv.yang.utils.video.fragment.RecorderVideoFragment
import kotlinx.android.synthetic.main.head.*

/**
 * 录制视频  自定义录制视频界面
 */
class RecordVideoActivity : ProActivity() {

    override fun handler(what: Int, arg1: Int, netInfo: NetInfo) {

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.record_video)
        tvTitle.text = "录制视频"

        imageBack.setOnClickListener {
            finish()
        }

        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED &&
            ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {

            val manger = supportFragmentManager
            val tt = manger.beginTransaction()
            tt.add(R.id.videoFragment, RecorderVideoFragment())
            tt.commit()

        } else {
            ActivityCompat.requestPermissions(
                this, arrayOf(
                    Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE
                ), 7777
            )

        }

    }

    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        if (requestCode == 7777) {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                val manger = supportFragmentManager
                val tt = manger.beginTransaction()
                tt.add(R.id.videoFragment, RecorderVideoFragment())
                tt.commit()
            }
        }
    }
}